<template>
  <!-- 选择日期 :placeholder="nowDate"-->
  <div class="conditions">
    <span class="title">选择日期</span>
    <i-select filterable 
              placeholder="请输入关键词搜索" v-model="type" :value="defult" style="width:50px">
      <i-option v-for="item in options" :key="item.value" :value="item.value">{{ item.label }}</i-option>
    </i-select>
    <Date-picker
      :type="type"
      :split-panels="type=='daterange'"
      :editable="false"
      @on-change="dateChange"
      v-model="value"
      :placeholder="placeholder"
      style="width: 200px"
    ></Date-picker>
  </div>
</template>

<script>
import util from "@/libs/util.js";
export default {
  props: {
    type: {
      type: String,
      default: "year"
    },
    disabled: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      options: [
        {
          label: "年",
          value: "year"
        },
        {
          label: "月",
          value: "month"
        },
        {
          label: "日",
          value: "date"
        }
      ],
      value: null
    };
  },
  computed: {
    placeholder: function() {
      return util.date.getNowFormatDate(this.type);
    }
  },
  methods: {
    dateChange(date) {
      this.$emit("input", date);
    }
  },
  watch: {
    type(val) {
      this.value = util.date.getNowFormatDate(val);
      this.$emit("input", util.date.getNowFormatDate(this.type));
    }
  },
  created() {
    if (this.disabled != null) {
      this.options = this.options.filter(item => {
        return item.value != this.disabled;
      });
    }
  },
  mounted() {
    this.$emit("input", util.date.getNowFormatDate(this.type));
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {} // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
